package com.jwell.panprovider.tools;


import android.util.Log;

import com.jwell.panprovider.application.UserState;
import com.jwell.panprovider.entity.Account;
import com.jwell.panprovider.entity.MeasurePlace;
import com.jwell.panprovider.entity.ProvinceBean;
import com.jwell.panprovider.entity.VersionBean;
import com.jwell.panprovider.model.WaybillListModel;

import java.util.List;


/**
 * 与 SharedPreferences相关的数据
 */
public class DataModel {
    private DataModel() {
    }

    public static DataModel getInstance() {
        return DataModelHolder.DATA_MODEL;
    }

    private static class DataModelHolder {
        private static final DataModel DATA_MODEL = new DataModel();
    }


    //获取用户状态
    public UserState getUserState() {
        UserState userState = SharedPreferencesUtils.get("UserState");
        Log.i("TAG", "获取的状态啊:" + userState);
        if (userState == null) {
            return UserState.FIRST;
        }
        return userState;
    }

    //设置用户状态
    public void setUserState(UserState userState) {
        SharedPreferencesUtils.save("UserState", userState);
    }


    //获取版本信息
    public VersionBean getVersionBean() {
        return SharedPreferencesUtils.get("VersionBean");
    }

    //存储版本信息
    public void saveVersionBean(VersionBean versionBean) {
        SharedPreferencesUtils.save("VersionBean", versionBean);
    }

    //存储地址
    public void saveAddress(List<ProvinceBean> list) {
        SharedPreferencesUtils.save("Address", list);
    }

    public List<ProvinceBean> getAddressList() {
        return SharedPreferencesUtils.get("Address");
    }

    public Account getAccount() {
        return SharedPreferencesUtils.get("Account");
    }

    //保存账户/密码
    public void setAccount(Account account) {
        SharedPreferencesUtils.save("Account", account);
    }

    public void removeAccount() {
        SharedPreferencesUtils.clear("Account");
    }

    //获取token值
    public String getToken() {
        return SharedPreferencesUtils.getString("token");
    }

    //存储token值
    public void saveToken(String token) {
        SharedPreferencesUtils.putString("token", token);
    }

    public void removeToken() {
        SharedPreferencesUtils.clear("token");
    }

    public String getUserName() {
        return SharedPreferencesUtils.getString("name");
    }

    //存储token值
    public void saveUserName(String token) {
        SharedPreferencesUtils.putString("name", token);
    }

    public void saveAllowOrNot(boolean isAllow) {
        SharedPreferencesUtils.putBoolean("isAllow", isAllow);
    }

    public Boolean isAllowSystemAlert() {
        return SharedPreferencesUtils.getBoolean("isAllow");
    }

    public void saveFirstState(boolean state) {
        SharedPreferencesUtils.putBoolean("firstToMain", state);
    }

    //存取计量点点信息
    public void saveMeasurePlace(List<MeasurePlace> permisison) {
        SharedPreferencesUtils.save("MeasurePlace", permisison);
    }

    public List<MeasurePlace> getMeasurePlace() {
        return SharedPreferencesUtils.get("MeasurePlace");
    }

    public Boolean getFirstToMain() {
        return SharedPreferencesUtils.getBoolean("firstToMain");
    }

    //登录界面自动登录
    public void setLoginCheckBox(boolean isChecked) {
        SharedPreferencesUtils.putBoolean("LoginCheckBox", isChecked);
    }

    public Boolean getLoginCheckBox() {
        return SharedPreferencesUtils.getBoolean("LoginCheckBox");
    }

    //存储运单最后一次搜索数据
    public void saveWaybillSearchData(WaybillListModel.RequestData requestData) {
        SharedPreferencesUtils.save("waybillRequestData", requestData);
    }

    public WaybillListModel.RequestData getWaybillSearchData() {
        return SharedPreferencesUtils.get("waybillRequestData");
    }
}
